﻿using System.Threading.Tasks;
using CSRedis;
using Microsoft.Extensions.Configuration;
using Volo.Abp.DependencyInjection;

namespace Linker.TaskCenter.Helpers
{
    public class CSRedisHelper : ISingletonDependency
    {
        private readonly CSRedisClient _client;

        public CSRedisHelper(IConfiguration configuration)
        {
            _client = new CSRedisClient(configuration["Redis:Configuration"]);
        }

        public CSRedisClient GetClient()
        {
            return _client;
        }


        public long Push<T>(string key, T data)
        {
            return _client.LPush(key, data);
        }


        public Task<long> PushAsync<T>(string key, T data)
        {
            return _client.LPushAsync(key, data);
        }


        public T BRPop<T>(string key)
        {
            return _client.BRPop<T>(3, key);
        }


        public long LRem<T>(string key, T data)
        {
            return _client.LRem(key, 0, data);
        }


        public Task<long> LRemAsync<T>(string key, T data)
        {
            return _client.LRemAsync(key, 0, data);
        }
    }
}